package ie.dit.reg08.manager;

import java.util.*;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class AttributeSet {
	Hashtable<String, String> htDescription;
	
	public AttributeSet(Node n) {
		htDescription = new Hashtable<String, String>();
		
		Node tmp;
		if(n.hasChildNodes()) {
			NodeList nl = n.getChildNodes();
			int num = nl.getLength();
			for(int i=0; i<num; i++ ) {
				tmp = nl.item(i);
				if(tmp.getNodeName().equals("ATTRIBUTE")){
					NamedNodeMap attributes = tmp.getAttributes();
					htDescription.put((attributes.getNamedItem("NAME")).getNodeValue(), (attributes.getNamedItem("VALUE")).getNodeValue());						
				}
			}
		} else {
			System.err.println("furnituredescription: no children!");
		}
	}

	public Hashtable<String, String> getHashtableDescription() {
		return htDescription;
	}
	
	public String getStringDescription() {
		String k,v;
		String s = "Description { ";
		Enumeration<String> e = htDescription.keys();
		while(e.hasMoreElements()) {
			k = e.nextElement();
			v = htDescription.get(k);
			s = s + k + ": " + v + " ";
		}
		s = s + "} End Descriptiion;";
		return s;
	}
	
	public boolean containsAttribute(String s) {
		return htDescription.containsKey(s);
	}
	
	public boolean containsOther() {
		return htDescription.containsKey("other");
	}
	public boolean containsType() {
		return htDescription.containsKey("type");
	}
	public boolean containsColour() {
		return htDescription.containsKey("colour");
	}
	public boolean containsSize() {
		return htDescription.containsKey("size");
	}
	public boolean containsOrientation() {
		return htDescription.containsKey("orientation");
	}
	public boolean containsXDimension() {
		return htDescription.containsKey("x-dimension");
	}
	public boolean containsYDimension() {
		return htDescription.containsKey("y-dimension");
	}

	
}
